articles

Home / DeveloperSection / Articles / How to display Base64 images in HTML

How to display Base64 images in HTML

How to display Base64 images in HTML

Ashutosh Kumar Verma 206 10-Jun-2024

HTML Base64 Images

To display a Base64 encoded image in HTML, you can use the img element by setting the src attribute to the Data URI that represents the Base64 encoded image data.

Syntax- 

<img src="base64-image-data" alt="Base64 Image">

Example- 

Here is a basic example showing the base64 image in HTML,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Base64 Image Example</title>
</head>
<body>

<h2>Base64 Image Example</h2>

<!-- Displaying a Base64 encoded image -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAJklEQVR42mL8//8/AwgwMSAA9CNFsQcDG0FYABRhsdU2SK+AAAAAElFTkSuQmCC" alt="Base64 Image">

</body>
</html>

In the above example-

The src attribute of the img element contains the Data URI that represents the Base64 encoded PNG image. The format of the data URI is data:[<mediatype>][;base64],<data>, where <mediatype> specifies the media type of the data (image/png in this case), and <data> is Base64 image data which is encoded.

Note  make sure replace the src data from your actual base64 image url

Output- 

How to display Base64 images in HTML

 

Also, Read: What is the use of HTML Iframe?


Updated 10-Jun-2024
Hi! This is Ashutosh Kumar Verma. I am a software developer at MindStick Software Pvt Ltd since 2021. I have added some new and interesting features to the MindStick website like a story section, audio section, and merge profile feature on MindStick subdomains, etc. I love coding and I have good knowledge of SQL Database.

Leave Comment

Comments

Liked By